package com.drafthj.study.spring5.ioc.metadata;

import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;

/**
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 *
 * @author drafthj
 * @date 2021/1/28
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class InstantiateContainer {
    public static void main(String[] args) {
        //way one
        ApplicationContext context = new ClassPathXmlApplicationContext("metadata/services.xml", "metadata/daos.xml",
                "metadata/factory.xml");
        System.out.println(context.getBean("petStore"));
        //alias
        System.out.println(context.getBean("aliasAccountDao"));
        //way two
        GenericApplicationContext genericContext = new GenericApplicationContext();
        new XmlBeanDefinitionReader(genericContext).loadBeanDefinitions("metadata/composed.xml");
        genericContext.refresh();
        System.out.println(genericContext.getBean("petStore"));
        //factory
        System.out.println(context.getBean("clientServiceInstance"));
        System.out.println(context.getBean("accountService"));
        System.out.println(context.getType("accountService"));
        System.out.println(context.getType("clientService"));
    }
}
